﻿using LevelEditor.Model.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace LevelEditor.View.Windows
{
    /// <summary>
    /// Interaction logic for LevelProperties.xaml
    /// </summary>
    public partial class LevelProperties : Window
    {

        private Level level;


        // Methods
        public LevelProperties()
        {
            this.InitializeComponent();
            this.okBtn.Click += new RoutedEventHandler(this.okBtn_Click);
            this.cancelBtn.Click += new RoutedEventHandler(this.cancelBtn_Click);
        }

        protected void cancelBtn_Click(object sender, RoutedEventArgs e)
        {
            this.Level = null;
            base.Close();
        }

        protected void okBtn_Click(object sender, RoutedEventArgs e)
        {
            if (this.Level == null)
            {
                this.Level = new Level();
                this.Level.Scene = new Scene();
            }
            this.Level.Name = this.name.Text;
            this.Level.Number = int.Parse(this.num.Text);
            this.Level.Scene.Width = int.Parse(this.width.Text);
            this.Level.Scene.Height = int.Parse(this.height.Text);
            base.Close();
        }

        // Properties
        public Level Level
        {
            get
            {
                return this.level;
            }
            set
            {
                this.level = value;
                if (this.level != null)
                {
                    this.name.Text = this.level.Name;
                    this.num.Text = this.level.Number.ToString();
                    this.width.Text = this.level.Scene.Width.ToString();
                    this.height.Text = this.level.Scene.Height.ToString();
                }
            }
        }
    }
}
